package org.index.api.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.index.entity.AdDataMapping;
import org.index.service.AdService;
import org.index.service.AdSource;
import org.index.service.impl.ResponseAdServiceImpl;
import org.shop.common.until.AbstractPageResult;

import com.alibaba.dubbo.config.annotation.Service;

@Service(
        version = "1.0.0",
        application = "${dubbo.application.id}",
        protocol = "${dubbo.protocol.id}",
        registry = "${dubbo.registry.id}"
)
public class AdImpl implements AdService<AdDataMapping>{
	
	@Resource
	private DataSource dataSource;
	
	@Override
	public List<AdDataMapping> getAdList() {
		// TODO Auto-generated method stub
		
		Map<String, String> param = new HashMap<>();
		
		
		AdSource<AdDataMapping> adImpl = new ResponseAdServiceImpl(param, "");
		
		
		return adImpl.getAdList();
	}

	@Override
	public AbstractPageResult<AdDataMapping> getBanner(Map<String, String> param) {
		
		AdSource<AdDataMapping> adImpl = new ResponseAdServiceImpl(param, "");
		
		return adImpl.getBanner();
		
	}
	
	 public ResultSet getRes()
	 {
		 	System.out.println(this.dataSource.toString());
			try {
				Connection jdbc = this.dataSource.getConnection();
				
				PreparedStatement pre = jdbc.prepareStatement("SELECT i.* FROM t_order o JOIN t_order_item i ON o.order_id=i.order_id WHERE o.user_id=? AND o.order_id=?");
				
				pre.setInt(1, 10);
				
				pre.setLong(2, Long.parseLong("154627235943284736"));
				
				pre.execute();
				
				ResultSet res = pre.getResultSet();
				
				return res;
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				
				return null;
			}
	 }
	
}
